<template>
    <div>
        <table>
            <tbody>
                <tr>
                    <td>名称</td>
                    <td>
                        <input type="text" v-model="date.houseName">
                    </td>
                </tr>
                <tr>
                    <td>房型</td>
                    <td>
                        <select v-model="date.houseTypeId">
                            <option value="0">请选择</option>
                            <option v-for="q in paii" :value="q.houseTypeId">{{ q.houseTypeName }}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>房号</td>
                    <td>
                        <select v-model="date.houseNumId">
                            <option value="0">请选择</option>
                            <option v-for="w in pai" :value="w.houseNumId">{{ w.houseNumName }}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>入住时间</td>
                    <td>
                        <input type="date" v-model="date.dates">
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <input type="button" value="修改" @click="update">
                    </td>
                </tr>
            </tbody>
        </table>
        <a href="/Show">返回显示列表</a>
    </div>
</template>

<script setup lang="ts">
import { ref,onMounted } from 'vue';
import moment from 'moment';
import { useRouter,useRoute } from 'vue-router';
import axios from 'axios';
const routher = useRouter();
const routhe = useRoute();
onMounted(()=>{
    leixing()
    leixings()
    xiu()
})
const xiu=()=>{
    var vid = routhe.query.id;
    axios.get("https://localhost:7144/api/House/GetHouse",{params:{id:vid}}).then(res=>{
        date.value=res.data;
        date.value.dates=moment(date.value.dates).format("YYYY-MM-DD")
    })
}
const update=()=>{
    axios.put("https://localhost:7144/api/House/XHouse",date.value).then(res=>{
        if(res.data>0){
            alert("更新成功")
            routher.push({path:"/Show"})
        }
        else{
            alert("更新失败")
        }
    })
}

const date=ref({
    "houseTypeId": 0,
    "houseId": 0,
    "houseNumId": 0,
    "houseName": "",
    "dates": "",
    "houseNumName": "",
    "houseTypeName": ""
})
//房好数量
const leixing=()=>{
    axios.get("https://localhost:7144/api/HouseNum/GetHouseNums").then(res=>{
        pai.value=res.data;
    })
}
const pai=ref([{
    "houseNumId": 0,
    "houseNumName": ""
}])
//房型类型
const leixings=()=>{
    axios.get("https://localhost:7144/api/HouseType/GetHouseTypes").then(res=>{
        paii.value=res.data;
    })
}
const paii=ref([{
    "houseTypeId": 0,
    "houseTypeName": ""
}])
</script>

<style scoped>

</style>